package com.skyit.bigevent.controller;

import com.skyit.bigevent.pojo.Article;
import com.skyit.bigevent.pojo.PageBean;
import com.skyit.bigevent.pojo.Result;
import com.skyit.bigevent.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Validated
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result add(@RequestBody @Validated(Article.Add.class) Article article) {
        articleService.add(article);
        return Result.success();
    }

    /**
     * 获取文章列表
     *
     * @return
     */
    @GetMapping
    public Result<PageBean<Article>> list(Integer pageNum, Integer pageSize
            , @RequestParam(required = false) Integer categoryId
            , @RequestParam(required = false) String state) {
        PageBean<Article> pageBean = articleService.list(pageNum, pageSize, categoryId, state);
        return Result.success(pageBean);
    }
}
